package org.example.blogger.service;

import lombok.extern.slf4j.Slf4j;
import org.example.blogger.mapper.BlogMapper;
import org.example.blogger.model.BlogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class BlogService {
    @Autowired
    private BlogMapper blogMapper;

    public List<BlogInfo> getList() {
        return blogMapper.selectAll();
    }


    public BlogInfo getBlogDetail(Integer blogId) {
        return blogMapper.selectById(blogId);
    }

    public Boolean insertBlog(BlogInfo blogInfo) {
        try {
            Integer result = blogMapper.insertBlog(blogInfo);
            if (result == 1) {
                return true;
            }
        }catch (Exception e){
            log.error("博客插入失败e,",e);
        }
        return false;
    }

    public Integer update(BlogInfo blogInfo) {
        try {
            Integer result = blogMapper.updateBlog(blogInfo);
            if (result == 1) {
                return result;
            }
        }catch (Exception e){
            log.error("博客删除失败e,",e);
        }
        return 0;
    }
}
